package com.cdtye.itps.cms.service.defect;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cdtye.common.mybatiscore.base.BaseService;
import com.cdtye.itps.cms.dao.enums.DelFlagEnum;
import com.cdtye.itps.cms.mapper.defect.JcjcDefectSourceTypeMapper;
import com.cdtye.itps.cms.dao.detect.JcjcDefectSourceTypeSection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class JcjcDefectSourceTypeService extends BaseService<JcjcDefectSourceTypeMapper, JcjcDefectSourceTypeSection> {
    @Autowired JcjcDefectSourceTypeMapper jcjcDefectSourceTypeMapper;

    @DS("tmis")
    public JcjcDefectSourceTypeSection findDefectSourceTypeByIdTmis(String Name){
        QueryWrapper<JcjcDefectSourceTypeSection> queryWrapper = new QueryWrapper<>();
        queryWrapper.and(wrapper  -> wrapper.eq("DEL_FLAG", DelFlagEnum.NO.value).or().isNull("DEL_FLAG"));
        queryWrapper.eq("source_type_name",Name);
        return jcjcDefectSourceTypeMapper.selectOne(queryWrapper);
    }


    @DS("tmis")
    public List<JcjcDefectSourceTypeSection> findOriginDateTmis(Date date){
        QueryWrapper<JcjcDefectSourceTypeSection> queryWrapper = new QueryWrapper<>();
        queryWrapper.and(wrapper  -> wrapper.eq("DEL_FLAG", DelFlagEnum.NO.value).or().isNull("DEL_FLAG"));
        queryWrapper.and(wrapper  ->
                wrapper.isNull("update_datetime").or().lt("update_datetime",date));
        return jcjcDefectSourceTypeMapper.selectList(queryWrapper);
    }




}
